package testPackage;

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int K = sc.nextInt();
        int result = numOfK(n,K);
        System.out.println(result);
    }
    public static  int numOfK(int n, int K){
        //将K转换成2进制
        int sum = 0;
        StringBuilder str = new StringBuilder();
        while(K != 0){
            if(K % 2 == 0){
                str.append('0');
            }else{
                str.append('1');
            }
            K = K << 1;
        }
        System.out.println("str"+str);
        for(int i = 0; i < str.length(); i++){
            if(str.charAt(i) == '1')
                sum += (int) Math.pow(n,i);
        }
        return sum;
    }
}
